package org.csmzxy.class2333;

import java.util.Comparator;
import java.util.TreeSet;

public class Example12 {
    public static void main(String[] args){
        TreeSet<Studeent2> set = new TreeSet<>(new Comparator<Studeent2>() {
            @Override
            public int compare(Studeent2 s1, Studeent2 s2) {
                int result = s1.getAge() - s2.getAge();
                result = result == 0 ?
                        s1.getName().compareTo(s2.getName()) : result;
                return result;
            }
        });
        set.add(new Studeent2("张三",18));
        set.add(new Studeent2("李四",25));
        set.add(new Studeent2("王五",20));
        set.add(new Studeent2("赵六",20));
        for (Studeent2 studeent2 : set){
            System.out.println(studeent2);
        }
    }
}
